﻿using System;
using System.Text;
using CtefCrmImport.Common.Enums;

namespace CtefCrmImport.Common.Models
{
    public class Donation
    {
        public string LineInput { get; set; }

        public Donor From { get; set; }

        public DateTime Date { get; set; }

        public DonationType FundType { get; set; }

        public PaymentType PaymentInstrument { get; set; }

        public decimal GiftAmount { get; set; }

        public decimal CompanyMatch { get; set; }

        public string Purpose { get; set; }

        public string RecognitionName { get; set; }

        public string TransactionId { get; set; }

        public string OtherInfo { get; set; }

        public decimal TotalAmount
        {
            get { return GiftAmount + CompanyMatch; }
        }

        public string AdditionalInfo
        {
            get 
            { 
                var buffer = new StringBuilder();
                buffer.AppendLine("Imported by CRM utility at " + DateTime.Now);

                if (!string.IsNullOrWhiteSpace(Purpose))
                {
                    buffer.AppendLine("Purpose: " + Purpose);
                }

                if (!string.IsNullOrWhiteSpace(RecognitionName))
                {
                    buffer.AppendLine("Recognition name: " + RecognitionName);
                }

                if (!string.IsNullOrWhiteSpace(OtherInfo))
                {
                    buffer.AppendLine(OtherInfo);
                }

                return buffer.ToString();
            }
        }

        public override string ToString()
        {
            var buffer = new StringBuilder();
            buffer.AppendLine("From: " + From.FullName);
            buffer.AppendLine("Date: " + Date);
            buffer.AppendLine("Gift amount: " + GiftAmount);
            buffer.AppendLine("Company match: " + CompanyMatch);
            buffer.AppendLine("Total amount: " + TotalAmount);
            buffer.AppendLine("Additional info: " + AdditionalInfo);

            return buffer.ToString();
        }
    }
}
